<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="顾问姓名">
              <j-input placeholder="请输入销售顾问姓名" v-model="queryParam.salesName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="顾问电话">
              <j-input placeholder="请输入销售顾问电话" v-model="queryParam.salesPhone"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="所属企业名">
              <j-input placeholder="所属企业名" v-model="queryParam.enterpriseName"></j-input>
            </a-form-item>
          </a-col>

          <!--        <template v-if="toggleSearchStatus">-->
          <!--    enterpriseId: "1385051814929514498"     -->
          <!--          </template>-->
          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('cxm-销售人员信息')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!--     <a-button  style="float:left;"  type="primary" icon="download" href="http://127.0.0.1:9090/fdcloud-boot/sys/common/static/temp/授权委托书.docx">下载授权书模板</a-button>
      <j-upload
        style="float:left;margin:0px 0px 3px 3px;"
        :returnUrl="true"
        text="上传人员授权书"
        :showUploadList="false"
        v-model="fileList"
        @change="handleChange"></j-upload> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <span slot="isInvalid" slot-scope="text, record">
          <span v-if="record.isInvalid == 0">离岗</span>
          <span v-if="record.isInvalid == 1">在岗</span>
          <span v-if="record.isInvalid == 2">转岗</span>
        </span>
        <span slot="isVerified" slot-scope="text, record">
          <span v-if="record.isVerified == 0">未认证</span>
          <span v-if="record.isVerified == 1">已认证</span>
        </span>
        <span slot="isBiaobing" slot-scope="text, record">
          <span v-if="record.isBiaobing == 0">不是</span>
          <span v-if="record.isBiaobing == 1">是</span>
        </span>
        <span slot="isAuthorized" slot-scope="text, record">
          <span v-if="record.isBiaobing == 0">不是</span>
          <span v-if="record.isBiaobing == 1">是</span>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <cxm-sales-info-modal ref="modalForm" @ok="modalFormOk"></cxm-sales-info-modal>
  </a-card>
</template>

<script>
import CxmSalesInfoModal from './modules/CxmSalesInfoModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { USER_INFO } from '@/store/mutation-types'
import Vue from 'vue'
import JUpload from '@comp/jeecg/JUpload'
import JInput from '@/components/jeecg/JInput'
import { getAction } from '@api/manage'
import { queryEnterprise } from '@/api/api'

export default {
  name: 'CxmSalesInfoList',
  mixins: [JeecgListMixin],
  components: {
    JUpload,
    CxmSalesInfoModal,
    JInput,
  },
  data() {
    return {
      fileList: [],
      description: 'cxm-销售顾问信息管理页面',
      enterpriseId: '',
      // 表头
      columns: [
        {
          title: '所属企业',
          align: 'center',
          dataIndex: 'enterpriseName',
        },
        {
          title: '顾问名',
          align: 'center',
          dataIndex: 'salesName',
        },
        {
          title: '电话',
          align: 'center',
          dataIndex: 'salesPhone',
        },

        {
          title: '是否在岗',
          align: 'center',
          dataIndex: 'isInvalid',
          scopedSlots: { customRender: 'isInvalid' },
        },
        {
          title: '是否实名',
          align: 'center',
          dataIndex: 'isVerified',
          scopedSlots: { customRender: 'isVerified' },
        },
        {
          title: '是否标兵',
          align: 'center',
          dataIndex: 'isBiaobing',
          scopedSlots: { customRender: 'isBiaobing' },
        },
        {
          title: '是否授权',
          align: 'center',
          dataIndex: 'isAuthorized',
          scopedSlots: { customRender: 'isAuthorized' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/cxm/cxmSalesInfo/list',
        delete: '/cxm/cxmSalesInfo/delete',
        deleteBatch: '/cxm/cxmSalesInfo/deleteBatch',
        exportXlsUrl: 'cxm/cxmSalesInfo/exportXls',
        importExcelUrl: 'cxm/cxmSalesInfo/importExcel',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${process.env.VUE_APP_BASE_API}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    open(record) {
      console.log('open', record)
      this.enterpriseId = record.id
      this.loadData(1)
    },
    searchReset() {
      this.queryParam = {}
      this.loadData(1)
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      //if (this.enterpriseId === '') return;
      let params = this.getQueryParams() //查询条件
      // params.enterpriseId = this.enterpriseId;
      //------------------查询企业id--------------------------
      let userinfo = Vue.ls.get(USER_INFO)
      let params2 = {
        enterpriseUscc: userinfo.enterpriseUscc,
      }
      queryEnterprise(params2).then((res2) => {
        console.log(userinfo.enterpriseUscc + '-=-=-=-=', res2.result)

        if (res2) {
          params.enterpriseId = res2.result.id
          /* params.enterpriseName = res2.result.id */
          getAction(this.url.list, params).then((res) => {
            if (res.success && res.result) {
              this.dataSource = res.result.records
              this.ipagination.total = res.result.total
            }
          })
        }
      })
      //-------------------------------------------
    },
    handleChange() {
      let userinfo = Vue.ls.get(USER_INFO)
      let CxmAuthorizationFile = {
        userId: userinfo.id,
        userName: userinfo.realname,
        enterpriseUscc: userinfo.enterpriseUscc,
        type: '2',
        filePath: this.fileList,
      }

      //暂时删除
      /* importFile(CxmAuthorizationFile).then((res) => {
          if (res.success) {
            //保存成功后提示
            that.$message.warning('上传成功!')
          } else {
            that.$message.warning('上传失败!')
          }
        }) */
    },
  },
  mounted() {
    //this.iframeWin = this.$refs.iframe.contentWindow
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>